package com.huawei.appgallery.forum.section.card;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import com.huawei.appgallery.forum.base.card.ForumCard;
import com.huawei.appgallery.forum.base.card.ForumCardBean;
import com.huawei.appgallery.forum.base.card.bean.ContributionInfo;
import com.huawei.appgallery.forum.base.card.bean.Section;
import com.huawei.appgallery.forum.section.bean.ForumSectionHeadCardBean;
import huawei.widget.HwButton;
import o.azb;
import o.bqx;
import o.bqy;
import o.brd;
import o.bsp;
import o.bst;
import o.bwx;
import o.cab.c;
import o.cab.e;
import o.cab.h;
import o.cab.i;
import o.cab.j;
import o.cbh;
import o.cdn;
import o.dof;
import o.epv;
import o.eqx;
import o.erq;
import o.evk;
import o.evx;
import o.fho;
import o.fjo;
import o.fjq;

public class ForumSectionHeadCard extends ForumCard {
    protected int ʻ = 0;
    protected TextView ʼ;
    protected TextView ʽ;
    protected HwButton ˊ;
    protected TextView ˊॱ;
    protected ImageView ˋ;
    protected LinearLayout ˋॱ;
    protected View ˎ;
    protected ImageView ˏ;
    protected TextView ˏॱ;
    protected ForumSectionHeadCardBean ͺ;
    protected View ॱ;
    protected LinearLayout ॱˊ;
    protected a ॱˎ;
    protected TextView ॱॱ;
    protected int ᐝ = 0;

    public interface a {
        void ˎ(Section section);
    }

    public ForumSectionHeadCard(Context context) {
        super(context);
    }

    public void ˏ(a aVar) {
        this.ॱˎ = aVar;
    }

    public View ˋ(LayoutInflater layoutInflater) {
        this.ॱ = layoutInflater.inflate(ʻ(), null);
        if (!(this instanceof BuoyForumSectionHeadCard)) {
            azb.ˏ(this.ॱ, e.ˊᐝ);
        }
        this.ˎ = this.ॱ.findViewById(e.ᐝॱ);
        this.ˏ = (ImageView) this.ॱ.findViewById(e.ʿ);
        this.ˋ = (ImageView) this.ॱ.findViewById(e.ˊˊ);
        this.ॱॱ = (TextView) this.ॱ.findViewById(e.ˉ);
        this.ˊ = (HwButton) this.ॱ.findViewById(e.ˋˊ);
        this.ˊ.setOnClickListener(new evx(this) {
            final /* synthetic */ ForumSectionHeadCard ॱ;

            {
                this.ॱ = r1;
            }

            public void ˋ(View view) {
                this.ॱ.ˊॱ();
            }
        });
        ॱˊ();
        this.ॱˊ = (LinearLayout) this.ॱ.findViewById(e.ͺ);
        this.ˊॱ = (TextView) this.ॱ.findViewById(e.ॱॱ);
        this.ˋॱ = (LinearLayout) this.ॱ.findViewById(e.ʻ);
        this.ˏॱ = (TextView) this.ॱ.findViewById(e.ᐝ);
        this.ʽ = (TextView) this.ॱ.findViewById(e.ॱᐝ);
        this.ʼ = (TextView) this.ॱ.findViewById(e.ˋॱ);
        ʽ();
        return this.ॱ;
    }

    protected void ʽ() {
    }

    public void ˏ(ForumSectionHeadCardBean forumSectionHeadCardBean) {
        if (forumSectionHeadCardBean != null) {
            this.ͺ = forumSectionHeadCardBean;
            Section ˊ = this.ͺ.ˊ();
            if (ˊ != null) {
                this.ᐝ = ˊ.ᐝ();
                if (ˎ()) {
                    eqx.ˏ(this.ˏ, ˊ.ॱ(), "app_default_icon");
                    if (!dof.ॱ(this.ͺ.ʼ())) {
                        try {
                            this.ˎ.setBackgroundColor(erq.ˊ(Color.parseColor(this.ͺ.ʼ()), 0.9f));
                        } catch (Exception e) {
                            bqx.ˋ("ForumSectionHeadCard", "parseColor error: " + this.ͺ.ʼ());
                        }
                    }
                }
                eqx.ˏ(this.ˋ, ˊ.ॱ(), "app_default_icon");
                this.ॱॱ.setText(ˊ.ˏ());
                ˏ(this.ᐝ);
                ʼ();
                ॱॱ();
            }
        }
    }

    protected boolean ˎ() {
        return true;
    }

    protected void ॱॱ() {
        long ˎ = this.ͺ.ˊ().ˎ();
        this.ʻ = this.ͺ.ˊ().ʻ();
        String ॱ = bst.ॱ(this.ʼॱ, ˎ);
        String ॱ2 = bst.ॱ(this.ʼॱ, (long) this.ʻ);
        CharSequence quantityString = this.ʼॱ.getResources().getQuantityString(h.ˊ, Long.valueOf(ˎ).intValue(), new Object[]{ॱ});
        CharSequence string = this.ʼॱ.getResources().getString(j.ˏॱ, new Object[]{ॱ2});
        this.ʽ.setText(quantityString);
        this.ʼ.setText(string);
    }

    protected void ʼ() {
        CharSequence ˋॱ = ˋॱ();
        CharSequence ˏॱ = ˏॱ();
        if (!TextUtils.isEmpty(ˋॱ) && !TextUtils.isEmpty(ˏॱ)) {
            this.ˊॱ.setText(ˋॱ);
            int ˎ = ˎ(true, true) / 2;
            int ॱ = ॱ(ˏ(this.ˊॱ, ˋॱ), ˎ);
            this.ˊॱ.setMaxWidth(ॱ(ˏ(this.ˏॱ, ˏॱ), ˎ) + ˎ);
            this.ˏॱ.setMaxWidth(ॱ + ˎ);
        } else if (!TextUtils.isEmpty(ˏॱ)) {
            this.ˏॱ.setMaxWidth(ˎ(false, true));
        } else if (!TextUtils.isEmpty(ˋॱ)) {
            this.ˊॱ.setText(ˋॱ);
            this.ˊॱ.setMaxWidth(ˎ(true, false));
            ((LayoutParams) this.ॱˊ.getLayoutParams()).setMarginEnd(0);
        }
    }

    private String ˏॱ() {
        if (TextUtils.isEmpty(this.ͺ.ʽ())) {
            this.ˋॱ.setVisibility(8);
            return null;
        }
        ForumCardBean forumCardBean = new ForumCardBean();
        forumCardBean.ॱ(this.ͺ.ʽ());
        this.ˋॱ.setTag(forumCardBean);
        this.ˋॱ.setOnClickListener(new evx(this) {
            final /* synthetic */ ForumSectionHeadCard ˏ;

            {
                this.ˏ = r1;
            }

            public void ˋ(View view) {
                this.ˏ.ॱᐝ();
                this.ˏ.ˋ().onClick(this.ˏ.ˋॱ);
            }
        });
        this.ˋॱ.setVisibility(0);
        return this.ʼॱ.getResources().getString(j.ᐝ);
    }

    private int ॱ(int i, int i2) {
        if (i > i2) {
            return 0;
        }
        return i2 - i;
    }

    private int ˏ(TextView textView, String str) {
        return (((int) textView.getPaint().measureText(str)) + textView.getPaddingLeft()) + textView.getPaddingRight();
    }

    private String ˋॱ() {
        ContributionInfo ᐝ = this.ͺ.ᐝ();
        if (ᐝ == null || ᐝ.ॱ() != 1) {
            this.ॱˊ.setVisibility(8);
            return null;
        }
        this.ॱˊ.setVisibility(0);
        String string;
        if (ᐝ.ˋ() == 1) {
            if (ᐝ.ˎ() < 0) {
                string = this.ʼॱ.getResources().getString(j.ʼॱ);
            } else {
                string = this.ʼॱ.getResources().getString(j.ᐝॱ, new Object[]{String.valueOf(r0)});
            }
            if (TextUtils.isEmpty(ᐝ.ˏ())) {
                return string;
            }
            final cbh o_cbh = (cbh) fho.ˏ().ˋ("User").ॱ(cbh.class);
            ForumCardBean forumCardBean = new ForumCardBean();
            forumCardBean.ॱ(ᐝ.ˏ());
            this.ॱˊ.setTag(forumCardBean);
            this.ॱˊ.setOnClickListener(new evx(this) {
                final /* synthetic */ ForumSectionHeadCard ˏ;

                public void ˋ(final View view) {
                    this.ˏ.ᐝॱ();
                    o_cbh.ˎ(this.ˏ.ʼॱ, 1).ˏ(new fjq<Boolean>(this) {
                        final /* synthetic */ AnonymousClass4 ˏ;

                        public void onComplete(fjo<Boolean> o_fjo_java_lang_Boolean) {
                            if (o_fjo_java_lang_Boolean.ˊ() && ((Boolean) o_fjo_java_lang_Boolean.ॱ()).booleanValue()) {
                                this.ˏ.ˏ.ˋ().onClick(view);
                            }
                        }
                    });
                }
            });
            return string;
        }
        string = this.ʼॱ.getResources().getString(j.ʼॱ);
        this.ॱˊ.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ ForumSectionHeadCard ˏ;

            {
                this.ˏ = r1;
            }

            public void onClick(View view) {
                this.ˏ.ᐝॱ();
                evk.ˏ(this.ˏ.ʼॱ.getString(j.ʻॱ));
            }
        });
        return string;
    }

    private void ॱˊ() {
        int ॱ;
        if (bsp.ˋ()) {
            ॱ = (int) (((float) epv.ॱ(this.ʼॱ)) / ͺ());
        } else {
            ॱ = (int) (((float) azb.ॱ(this.ʼॱ)) / 1.7777778f);
        }
        ˊ(this.ˎ, -1, ॱ);
        ˊ(this.ˏ, -1, ॱ);
    }

    private float ͺ() {
        if (cdn.ॱॱ()) {
            return 3.4188035f;
        }
        return 1.7777778f;
    }

    protected void ˊ(View view, int i, int i2) {
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        if (layoutParams == null) {
            layoutParams = new ViewGroup.LayoutParams(-1, -2);
        }
        layoutParams.width = i;
        layoutParams.height = i2;
        view.setLayoutParams(layoutParams);
    }

    private void ˊॱ() {
        int i = 1;
        if (1 != this.ᐝ) {
            i = 0;
        }
        ((bwx) fho.ˏ().ˋ("Operation").ॱ(bwx.class)).ˊ(this.ʼॱ, this.ͺ.ˊ(), i, this.ͺ.ॱ(), ᐝ()).ˏ(new fjq<Boolean>(this) {
            final /* synthetic */ ForumSectionHeadCard ˋ;

            public void onComplete(fjo<Boolean> o_fjo_java_lang_Boolean) {
                if (o_fjo_java_lang_Boolean.ˊ() && ((Boolean) o_fjo_java_lang_Boolean.ॱ()).booleanValue()) {
                    ForumSectionHeadCard forumSectionHeadCard;
                    if (i == 0) {
                        this.ˋ.ͺ.ˊ().ˊ(1);
                        this.ˋ.ᐝ = 1;
                        this.ˋ.ˏ(1);
                        forumSectionHeadCard = this.ˋ;
                        forumSectionHeadCard.ʻ++;
                        this.ˋ.ͺ.ˊ().ˎ(this.ˋ.ʻ);
                        this.ˋ.ॱॱ();
                    } else {
                        this.ˋ.ͺ.ˊ().ˊ(0);
                        this.ˋ.ᐝ = 0;
                        this.ˋ.ˏ(0);
                        forumSectionHeadCard = this.ˋ;
                        forumSectionHeadCard.ʻ--;
                        this.ˋ.ͺ.ˊ().ˎ(this.ˋ.ʻ);
                        this.ˋ.ॱॱ();
                    }
                    if (this.ˋ.ॱˎ != null) {
                        this.ˋ.ॱˎ.ˎ(this.ˋ.ͺ.ˊ());
                    }
                    this.ˋ.ˋ(i);
                }
            }
        });
    }

    protected boolean ᐝ() {
        return false;
    }

    protected void ˏ(int i) {
        if (i == 1) {
            this.ˊ.setText(j.ʽ);
        } else {
            this.ˊ.setText(j.ʻ);
        }
    }

    private int ˎ(boolean z, boolean z2) {
        int ॱ = (azb.ॱ(this.ʼॱ) - (this.ʼॱ.getResources().getDimensionPixelSize(c.ॱ) * 3)) - this.ʼॱ.getResources().getDimensionPixelSize(c.ॱˎ);
        if (z && z2) {
            return (ॱ - (this.ʼॱ.getResources().getDimensionPixelSize(c.ॱˊ) * 2)) - this.ʼॱ.getResources().getDimensionPixelSize(c.ॱ);
        }
        return ॱ - this.ʼॱ.getResources().getDimensionPixelSize(c.ॱˊ);
    }

    private void ᐝॱ() {
        Section ˊ = this.ͺ.ˊ();
        if (ˊ != null) {
            brd.ॱ.ˋ(bqy.ˋ().ˎ(this.ʼॱ), bqy.ˋ().ˎ(), ˊ.ˊ());
        }
    }

    private void ॱᐝ() {
        Section ˊ = this.ͺ.ˊ();
        if (ˊ != null) {
            brd.ॱ.ˎ(bqy.ˋ().ˎ(this.ʼॱ), bqy.ˋ().ˎ(), ˊ.ˊ());
        }
    }

    private void ˋ(int i) {
        Section ˊ = this.ͺ.ˊ();
        if (ˊ != null) {
            brd.ॱ.ˏ(bqy.ˋ().ˎ(this.ʼॱ), bqy.ˋ().ˎ(), ˊ.ˊ(), i == 0 ? 1 : 0);
        }
    }

    protected int ʻ() {
        return i.ʾ;
    }
}
